package test07;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set; /**
 * 幻觉内容检测处理器（新增检测器示例）
 */
public class HallucinationHandler extends ContentHandler {
    private Set<String> factCheckDatabase;
    private String consistencyModel = "fact-consistency-v2";

    public HallucinationHandler() {
        super("幻觉内容检测器");
        initializeFactDatabase();
    }

    private void initializeFactDatabase() {
        factCheckDatabase = new HashSet<>(Arrays.asList(
                "地球是圆的", "水在100摄氏度沸腾", "中国首都是北京"
        ));
    }

    @Override
    protected boolean canHandle(ContentCheckRequest request) {
        return request.getContentType() == ContentType.TEXT ||
                request.getContentType() == ContentType.MULTIMODAL;
    }

    @Override
    protected CheckResult doCheck(ContentCheckRequest request) {
        String content = request.getContentData().toString();

        // 模拟事实一致性检查
        boolean hasHallucination = Math.random() < 0.3; // 30%概率检测到幻觉

        if (hasHallucination) {
            return new CheckResult(true, RiskLevel.MEDIUM,
                    "检测到可能的事实错误或幻觉内容", 0.78, "REVIEW");
        }

        return new CheckResult(true, RiskLevel.LOW, "内容事实一致性良好", 0.85, "PASS");
    }

    public void addFact(String fact) {
        factCheckDatabase.add(fact);
    }
}
